Techniques for comprehensively synchronizing execution threads

ABSTRACT

A synchronization instruction causes a processor to ensure that specified threads included within a warp concurrently execute a single subsequent instruction. The specified threads include at least a first thread and a second thread. In operation, the first thread arrives at the synchronization instruction. The processor determines that the second thread has not yet arrived at the synchronization instruction and configures the first thread to stop executing instructions. After issuing at least one instruction for the second thread, the processor determines that all the specified threads have arrived at the synchronization instruction. The processor then causes all the specified threads to execute the subsequent instruction. Advantageously, unlike conventional approaches to synchronizing threads, the synchronization instruction enables the processor to reliably and properly execute code that includes complex control flows and/or instructions that presuppose that threads are converged.

BACKGROUND OF THE INVENTION

Field of the Invention

Embodiments of the present invention relate generally to parallelprocessing systems and, more specifically, to techniques forcomprehensively synchronizing execution threads.

Description of the Related Art

Graphics processing units (GPUs) are capable of very high performanceusing a relatively large number of small, parallel execution threads ondedicated programmable hardware processing units. In GPUs, a “threadgroup” or “warp” refers to a group of threads that, in general,concurrently execute the same instructions on different input data.However, developers may write code that, when executing on the GPU,causes only a portion of the threads in the warp to execute aninstruction. The threads in the warp are referred to as “diverged”during the execution of this type of instruction. An example of codethat causes such a divergence is code written in the C programminglanguage that includes an “if” statement that results in two or moresequences of instructions, where a different set of threads in a warpfollows each of the sequences.

One limitation of GPUs is that the proper behavior of some instructionspresupposes that the threads in each warp are converged. For example, aGPU may implement a shuffle instruction that allows directregister-to-register data exchange between threads in a warp. If a GPUattempts to execute a shuffle instruction on a warp when the threads arediverged, then the results are unpredictable. For instance, the codethat is executing on the GPU may produce incorrect results or terminateunexpectedly.

Although some compilers and GPUs implement some level of synchronizationfunctionality, that functionality is limited and does not guaranteeconvergence for all situations. For example, many GPUs implement abarrier instruction that is intended to synchronize warps. However, thebarrier instruction presupposes that the threads in each of the warpshave converged and, consequently, is unreliable. In another example,some compilers analyze the code to detect relatively simple divergencepatterns. Upon detecting a divergence pattern, the compilers bracket thedivergent instructions between two instructions that, respectively,indicate a re-convergence point and continue execution at there-convergence point. However, the compilers are unable to analyzecertain types of complicated control flows and, consequently, thecompilers are not always able to ensure that threads within a warp areconverged when required for proper execution of the code.

As a general matter, the implementation of certain program instructionsmay require a level of convergence across the different threads in awarp that cannot be maintained by the compiler and hardware mechanismsincluded in the GPU that are normally tasked with ensuring such threadconvergence. Accordingly, the only way to ensure proper execution ofcode is for the programmer to write code in programming languages thatdo not support complex control flows or write code only using limitedsubsets of instruction and operations defined richer programminglanguages. Restricting code in either of these ways would dramaticallyreduce the ability of programmers to efficiently configure GPUs, whichis undesirable.

As the foregoing illustrates, what is needed in the art are moreeffective techniques for synchronizing execution threads within a threadgroup or warp.

SUMMARY OF THE PRESENT INVENTION

One embodiment of the present invention sets forth acomputer-implemented method for synchronizing a plurality of threadsincluded within a warp to concurrently execute a single subsequentinstruction. The method includes determining that a first threadincluded in the plurality of threads has arrived at a synchronizationinstruction that specifies the plurality of threads; determining that asecond thread included in the plurality of threads has not yet arrivedat the synchronization instruction; configuring the first thread to stopexecuting instructions; issuing at least one instruction for the secondthread; determining that all the threads included in the plurality ofthreads have arrived at the synchronization instruction; and causing allthe threads included in the plurality of threads to execute the singlesubsequent instruction.

One advantage of the disclosed techniques is that the techniques enableprocessors to reliably and properly execute code and instructions thatrely on the convergence of different threads included within a warp. Bycontrast, conventional hardware mechanisms included in conventionalprocessors are not always able to ensure that threads within a warp areconverged when required for proper execution of code and instructions.

BRIEF DESCRIPTION OF THE DRAWINGS

So that the manner in which the above recited features of the presentinvention can be understood in detail, a more particular description ofthe invention, briefly summarized above, may be had by reference toembodiments, some of which are illustrated in the appended drawings. Itis to be noted, however, that the appended drawings illustrate onlytypical embodiments of this invention and are therefore not to beconsidered limiting of its scope, for the invention may admit to otherequally effective embodiments.

FIG. 1 is a block diagram illustrating a computer system configured toimplement one or more aspects of the present invention;

FIG. 2 is a block diagram of a parallel processing unit included in theparallel processing subsystem of FIG. 1, according to variousembodiments of the present invention;

FIG. 3 is a block diagram of a general processing cluster included inthe parallel processing unit of FIG. 2, according to various embodimentsof the present invention;

FIG. 4 is a block diagram of a streaming multiprocessor included in thegeneral processing cluster of FIG. 3, according to various embodimentsof the present invention;

FIG. 5 is an example instruction sequence performed by the streamingmultiprocessor of FIG. 4 to synchronize different threads includedwithin a warp prior to concurrently executing a single subsequentinstruction, according to various embodiments of the present invention;and

FIG. 6 is a flow diagram of method steps for synchronizing differentthreads included within a warp prior to concurrently executing a singlesubsequent instruction, according to various embodiments of the presentinvention.

DETAILED DESCRIPTION

In the following description, numerous specific details are set forth toprovide a more thorough understanding of the present invention. However,it will be apparent to one of skill in the art that the presentinvention may be practiced without one or more of these specificdetails.

System Overview

FIG. 1 is a block diagram illustrating a computer system 100 configuredto implement one or more aspects of the present invention. As shown,computer system 100 includes, without limitation, a central processingunit (CPU) 102 and a system memory 104 coupled to a parallel processingsubsystem 112 via a memory bridge 105 and a communication path 113.Memory bridge 105 is further coupled to an I/O (input/output) bridge 107via a communication path 106, and I/O bridge 107 is, in turn, coupled toa switch 116.

In operation, I/O bridge 107 is configured to receive user inputinformation from input devices 108, such as a keyboard or a mouse, andforward the input information to CPU 102 for processing viacommunication path 106 and memory bridge 105. Switch 116 is configuredto provide connections between I/O bridge 107 and other components ofthe computer system 100, such as a network adapter 118 and variousadd-in cards 120 and 121.

As also shown, I/O bridge 107 is coupled to a system disk 114 that maybe configured to store content and applications and data for use by CPU102 and parallel processing subsystem 112. As a general matter, systemdisk 114 provides non-volatile storage for applications and data and mayinclude fixed or removable hard disk drives, flash memory devices, andCD-ROM (compact disc read-only-memory), DVD-ROM (digital versatiledisc-ROM), Blu-ray, HD-DVD (high definition DVD), or other magnetic,optical, or solid state storage devices. Finally, although notexplicitly shown, other components, such as universal serial bus orother port connections, compact disc drives, digital versatile discdrives, film recording devices, and the like, may be connected to I/Obridge 107 as well.

In various embodiments, memory bridge 105 may be a Northbridge chip, andI/O bridge 107 may be a Southbrige chip. In addition, communicationpaths 106 and 113, as well as other communication paths within computersystem 100, may be implemented using any technically suitable protocols,including, without limitation, AGP (Accelerated Graphics Port),HyperTransport, or any other bus or point-to-point communicationprotocol known in the art.

In some embodiments, parallel processing subsystem 112 comprises agraphics subsystem that delivers pixels to a display device 110 that maybe any conventional cathode ray tube, liquid crystal display,light-emitting diode display, or the like. In such embodiments, theparallel processing subsystem 112 incorporates circuitry optimized forgraphics and video processing, including, for example, video outputcircuitry. As described in greater detail below in FIG. 2, suchcircuitry may be incorporated across one or more parallel processingunits (PPUs) included within parallel processing subsystem 112. In otherembodiments, the parallel processing subsystem 112 incorporatescircuitry optimized for general purpose and/or compute processing.Again, such circuitry may be incorporated across one or more PPUsincluded within parallel processing subsystem 112 that are configured toperform such general purpose and/or compute operations. In yet otherembodiments, the one or more PPUs included within parallel processingsubsystem 112 may be configured to perform graphics processing, generalpurpose processing, and compute processing operations. System memory 104includes at least one device driver 103 configured to manage theprocessing operations of the one or more PPUs within parallel processingsubsystem 112.

In various embodiments, parallel processing subsystem 112 may beintegrated with one or more other the other elements of FIG. 1 to form asingle system. For example, parallel processing subsystem 112 may beintegrated with CPU 102 and other connection circuitry on a single chipto form a system on chip (SoC).

It will be appreciated that the system shown herein is illustrative andthat variations and modifications are possible. The connection topology,including the number and arrangement of bridges, the number of CPUs 102,and the number of parallel processing subsystems 112, may be modified asdesired. For example, in some embodiments, system memory 104 could beconnected to CPU 102 directly rather than through memory bridge 105, andother devices would communicate with system memory 104 via memory bridge105 and CPU 102. In other alternative topologies, parallel processingsubsystem 112 may be connected to I/O bridge 107 or directly to CPU 102,rather than to memory bridge 105. In still other embodiments, I/O bridge107 and memory bridge 105 may be integrated into a single chip insteadof existing as one or more discrete devices. Lastly, in certainembodiments, one or more components shown in FIG. 1 may not be present.For example, switch 116 could be eliminated, and network adapter 118 andadd-in cards 120, 121 would connect directly to I/O bridge 107.

FIG. 2 is a block diagram of a parallel processing unit (PPU) 202included in the parallel processing subsystem 112 of FIG. 1, accordingto one embodiment of the present invention. Although FIG. 2 depicts onePPU 202, as indicated above, parallel processing subsystem 112 mayinclude any number of PPUs 202. As shown, PPU 202 is coupled to a localparallel processing (PP) memory 204. PPU 202 and PP memory 204 may beimplemented using one or more integrated circuit devices, such asprogrammable processors, application specific integrated circuits(ASICs), or memory devices, or in any other technically feasiblefashion.

In some embodiments, PPU 202 comprises a graphics processing unit (GPU)that may be configured to implement a graphics rendering pipeline toperform various operations related to generating pixel data based ongraphics data supplied by CPU 102 and/or system memory 104. Whenprocessing graphics data, PP memory 204 can be used as graphics memorythat stores one or more conventional frame buffers and, if needed, oneor more other render targets as well. Among other things, PP memory 204may be used to store and update pixel data and deliver final pixel dataor display frames to display device 110 for display. In someembodiments, PPU 202 also may be configured for general-purposeprocessing and compute operations.

In operation, CPU 102 is the master processor of computer system 100,controlling and coordinating operations of other system components. Inparticular, CPU 102 issues commands that control the operation of PPU202. In some embodiments, CPU 102 writes a stream of commands for PPU202 to a data structure (not explicitly shown in either FIG. 1 or FIG.2) that may be located in system memory 104, PP memory 204, or anotherstorage location accessible to both CPU 102 and PPU 202. A pointer tothe data structure is written to a pushbuffer to initiate processing ofthe stream of commands in the data structure. The PPU 202 reads commandstreams from the pushbuffer and then executes commands asynchronouslyrelative to the operation of CPU 102. In embodiments where multiplepushbuffers are generated, execution priorities may be specified foreach pushbuffer by an application program via device driver 103 tocontrol scheduling of the different pushbuffers.

As also shown, PPU 202 includes an I/O (input/output) unit 205 thatcommunicates with the rest of computer system 100 via the communicationpath 113 and memory bridge 105. I/O unit 205 generates packets (or othersignals) for transmission on communication path 113 and also receivesall incoming packets (or other signals) from communication path 113,directing the incoming packets to appropriate components of PPU 202. Forexample, commands related to processing tasks may be directed to a hostinterface 206, while commands related to memory operations (e.g.,reading from or writing to PP memory 204) may be directed to a crossbarunit 210. Host interface 206 reads each pushbuffer and transmits thecommand stream stored in the pushbuffer to a front end 212.

As mentioned above in conjunction with FIG. 1, the connection of PPU 202to the rest of computer system 100 may be varied. In some embodiments,parallel processing subsystem 112, which includes at least one PPU 202,is implemented as an add-in card that can be inserted into an expansionslot of computer system 100. In other embodiments, PPU 202 can beintegrated on a single chip with a bus bridge, such as memory bridge 105or I/O bridge 107. Again, in still other embodiments, some or all of theelements of PPU 202 may be included along with CPU 102 in a singleintegrated circuit or system of chip (SoC).

In operation, front end 212 transmits processing tasks received fromhost interface 206 to a work distribution unit (not shown) withintask/work unit 207. The work distribution unit receives pointers toprocessing tasks that are encoded as task metadata (TMD) and stored inmemory. The pointers to TMDs are included in a command stream that isstored as a pushbuffer and received by the front end unit 212 from thehost interface 206. Processing tasks that may be encoded as TMDs includeindices associated with the data to be processed as well as stateparameters and commands that define how the data is to be processed. Forexample, the state parameters and commands could define the program tobe executed on the data. The task/work unit 207 receives tasks from thefront end 212 and ensures that GPCs 208 are configured to a valid statebefore the processing task specified by each one of the TMDs isinitiated. A priority may be specified for each TMD that is used toschedule the execution of the processing task. Processing tasks also maybe received from the processing cluster array 230. Optionally, the TMDmay include a parameter that controls whether the TMD is added to thehead or the tail of a list of processing tasks (or to a list of pointersto the processing tasks), thereby providing another level of controlover execution priority.

PPU 202 advantageously implements a highly parallel processingarchitecture based on a processing cluster array 230 that includes a setof C general processing clusters (GPCs) 208, where C≥1. Each GPC 208 iscapable of executing a large number (e.g., hundreds or thousands) ofthreads concurrently, where each thread is an instance of a program. Invarious applications, different GPCs 208 may be allocated for processingdifferent types of programs or for performing different types ofcomputations. The allocation of GPCs 208 may vary depending on theworkload arising for each type of program or computation.

Memory interface 214 includes a set of D of partition units 215, whereD≥1. Each partition unit 215 is coupled to one or more dynamic randomaccess memories (DRAMs) 220 residing within PPM memory 204. In oneembodiment, the number of partition units 215 equals the number of DRAMs220, and each partition unit 215 is coupled to a different DRAM 220. Inother embodiments, the number of partition units 215 may be differentthan the number of DRAMs 220. Persons of ordinary skill in the art willappreciate that a DRAM 220 may be replaced with any other technicallysuitable storage device. In operation, various render targets, such astexture maps and frame buffers, may be stored across DRAMs 220, allowingpartition units 215 to write portions of each render target in parallelto efficiently use the available bandwidth of PP memory 204.

A given GPCs 208 may process data to be written to any of the DRAMs 220within PP memory 204. Crossbar unit 210 is configured to route theoutput of each GPC 208 to the input of any partition unit 215 or to anyother GPC 208 for further processing. GPCs 208 communicate with memoryinterface 214 via crossbar unit 210 to read from or write to variousDRAMs 220. In one embodiment, crossbar unit 210 has a connection to I/Ounit 205, in addition to a connection to PP memory 204 via memoryinterface 214, thereby enabling the processing cores within thedifferent GPCs 208 to communicate with system memory 104 or other memorynot local to PPU 202. In the embodiment of FIG. 2, crossbar unit 210 isdirectly connected with I/O unit 205. In various embodiments, crossbarunit 210 may use virtual channels to separate traffic streams betweenthe GPCs 208 and partition units 215.

Again, GPCs 208 can be programmed to execute processing tasks relatingto a wide variety of applications, including, without limitation, linearand nonlinear data transforms, filtering of video and/or audio data,modeling operations (e.g., applying laws of physics to determineposition, velocity and other attributes of objects), image renderingoperations (e.g., tessellation shader, vertex shader, geometry shader,and/or pixel/fragment shader programs), general compute operations, etc.In operation, PPU 202 is configured to transfer data from system memory104 and/or PP memory 204 to one or more on-chip memory units, processthe data, and write result data back to system memory 104 and/or PPmemory 204. The result data may then be accessed by other systemcomponents, including CPU 102, another PPU 202 within parallelprocessing subsystem 112, or another parallel processing subsystem 112within computer system 100.

As noted above, any number of PPUs 202 may be included in a parallelprocessing subsystem 112. For example, multiple PPUs 202 may be providedon a single add-in card, or multiple add-in cards may be connected tocommunication path 113, or one or more of PPUs 202 may be integratedinto a bridge chip. PPUs 202 in a multi-PPU system may be identical toor different from one another. For example, different PPUs 202 mighthave different numbers of processing cores and/or different amounts ofPP memory 204. In implementations where multiple PPUs 202 are present,those PPUs may be operated in parallel to process data at a higherthroughput than is possible with a single PPU 202. Systems incorporatingone or more PPUs 202 may be implemented in a variety of configurationsand form factors, including, without limitation, desktops, laptops,handheld personal computers or other handheld devices, servers,workstations, game consoles, embedded systems, and the like.

FIG. 3 is a block diagram of a GPC 208 included in PPU 202 of FIG. 2,according to one embodiment of the present invention. In operation, GPC208 may be configured to execute a large number of threads in parallelto perform graphics, general processing and/or compute operations. Asused herein, a “thread” refers to an instance of a particular programexecuting on a particular set of input data. In some embodiments,single-instruction, multiple-data (SIMD) instruction issue techniquesare used to support parallel execution of a large number of threadswithout providing multiple independent instruction units. In otherembodiments, single-instruction, multiple-thread (SIMT) techniques areused to support parallel execution of a large number of generallysynchronized threads, using a common instruction unit configured toissue instructions to a set of processing engines within GPC 208. Unlikea SIMD execution regime, where all processing engines typically executeidentical instructions, SIMT execution allows different threads to morereadily follow divergent execution paths through a given program.Persons of ordinary skill in the art will understand that a SIMDprocessing regime represents a functional subset of a SIMT processingregime.

Operation of GPC 208 is controlled via a pipeline manager 305 thatdistributes processing tasks received from a work distribution unit (notshown) within task/work unit 207 to one or more streamingmultiprocessors (SMs) 310. Pipeline manager 305 may also be configuredto control a work distribution crossbar 330 by specifying destinationsfor processed data output by SMs 310.

In one embodiment, GPC 208 includes a set of M of SMs 310, where M≥1.Also, each SM 310 includes a set of functional execution units (notshown), such as execution units and load-store units. Processingoperations specific to any of the functional execution units may bepipelined, which enables a new instruction to be issued for executionbefore a previous instruction has completed execution. Any combinationof functional execution units within a given SM 310 may be provided. Invarious embodiments, the functional execution units may be configured tosupport a variety of different operations including integer and floatingpoint arithmetic (e.g., addition and multiplication), comparisonoperations, Boolean operations (AND, OR, XOR), bit-shifting, andcomputation of various algebraic functions (e.g., planar interpolationand trigonometric, exponential, and logarithmic functions, etc.).Advantageously, the same functional execution unit can be configured toperform different operations.

In operation, each SM 310 is configured to process one or more threadgroups. As used herein, a “thread group” or “warp” refers to a group ofthreads concurrently executing the same program on different input data,with one thread of the group being assigned to a different executionunit within an SM 310. A thread group may include fewer threads than thenumber of execution units within the SM 310, in which case some of theexecution may be idle during cycles when that thread group is beingprocessed. A thread group may also include more threads than the numberof execution units within the SM 310, in which case processing may occurover consecutive clock cycles. Since each SM 310 can support up to Gthread groups concurrently, it follows that up to G*M thread groups canbe executing in GPC 208 at any given time.

Additionally, a plurality of related thread groups may be active (indifferent phases of execution) at the same time within an SM 310. Thiscollection of thread groups is referred to herein as a “cooperativethread array” (“CTA”) or “thread array.” The size of a particular CTA isequal to m*k, where k is the number of concurrently executing threads ina thread group, which is typically an integer multiple of the number ofexecution units within the SM 310, and m is the number of thread groupssimultaneously active within the SM 310.

Although not shown in FIG. 3, each SM 310 contains a level one (L1)cache or uses space in a corresponding L1 cache outside of the SM 310 tosupport, among other things, load and store operations performed by theexecution units. Each SM 310 also has access to level two (L2) caches(not shown) that are shared among all GPCs 208 in PPU 202. The L2 cachesmay be used to transfer data between threads. Finally, SMs 310 also haveaccess to off-chip “global” memory, which may include PP memory 204and/or system memory 104. It is to be understood that any memoryexternal to PPU 202 may be used as global memory. Additionally, as shownin FIG. 3, a level one-point-five (L1.5) cache 335 may be includedwithin GPC 208 and configured to receive and hold data requested frommemory via memory interface 214 by SM 310. Such data may include,without limitation, instructions, uniform data, and constant data. Inembodiments having multiple SMs 310 within GPC 208, the SMs 310 maybeneficially share common instructions and data cached in L1.5 cache335.

Each GPC 208 may have an associated memory management unit (MMU) 320that is configured to map virtual addresses into physical addresses. Invarious embodiments, MMU 320 may reside either within GPC 208 or withinthe memory interface 214. The MMU 320 includes a set of page tableentries (PTEs) used to map a virtual address to a physical address of atile or memory page and optionally a cache line index. The MMU 320 mayinclude address translation lookaside buffers (TLB) or caches that mayreside within SMs 310, within one or more L1 caches, or within GPC 208.

In graphics and compute applications, GPC 208 may be configured suchthat each SM 310 is coupled to a texture unit 315 for performing texturemapping operations, such as determining texture sample positions,reading texture data, and filtering texture data.

In operation, each SM 310 transmits a processed task to workdistribution crossbar 330 in order to provide the processed task toanother GPC 208 for further processing or to store the processed task inan L2 cache (not shown), parallel processing memory 204, or systemmemory 104 via crossbar unit 210. In addition, a pre-raster operations(preROP) unit 325 is configured to receive data from SM 310, direct datato one or more raster operations (ROP) units within partition units 215,perform optimizations for color blending, organize pixel color data, andperform address translations.

It will be appreciated that the core architecture described herein isillustrative and that variations and modifications are possible. Amongother things, any number of processing units, such as SMs 310, textureunits 315, or preROP units 325, may be included within GPC 208. Further,as described above in conjunction with FIG. 2, PPU 202 may include anynumber of GPCs 208 that are configured to be functionally similar to oneanother so that execution behavior does not depend on which GPC 208receives a particular processing task. Further, each GPC 208 operatesindependently of the other GPCs 208 in PPU 202 to execute tasks for oneor more application programs. In view of the foregoing, persons ofordinary skill in the art will appreciate that the architecturedescribed in FIGS. 1-3A in no way limits the scope of the presentinvention.

FIG. 4 is a block diagram of a streaming multiprocessor (SM) 310included in the general processing cluster (GPC) 208 of FIG. 3,according to various embodiments of the present invention. As shown, theSM 310 includes, without limitation, any number of subpartition units430, an interconnect network 480, an SM cache 490, and a convergencebarrier unit (CBU) 420.

As shown, the subpartition units 430 and the CBU 420 are connected tothe SM cache 490 via the interconnect network 480. In variousembodiments, the interconnect network 480 may be configured to enablethe subpartition units 430 and the CBU 420 to access informationincluded in any number and type of registers as well as memory locationsincluded in the SM cache 490. The SM cache 490 may comprise any type andamount of on-chip memory. For instance, in various embodiments, the SMcache 490 may comprise shared memory, L1 cache memory, or a combinationthereof.

In general, each of the subpartition units 430 may be assigned anynumber of warps, however a given warp is assigned to only onesubpartition unit 430. As shown, each of the subpartition units 430includes, without limitation, an instruction cache 440, an instructionscheduler 450, and a core datapath 460. As described in conjunction withFIG. 3, the SM 310 receives processing tasks from the pipeline manager305. For each warp, the assigned subpartition unit 430 receives theassigned processing tasks and stores the associated instructions in theinstruction cache 440. The instruction scheduler 450 issues instructionsfor various threads included in the assigned warps.

The core datapath 460 includes, without limitation, functional units(not shown) and a register file 407. The functional units perform anynumber and type of operations to execute threads assigned to theassociated subpartition unit 430. The register file 407 provides a setof registers that may be implemented and arranged in any technicallyfeasible fashion. For example, the register file 407 could be dividedbetween the different warps assigned to the subpartition unit 430.

As is well known, developers may write code that, when executing on theSM 310, causes only a portion of the threads in a warp to execute aninstruction. The threads in the warp are referred to herein as“diverged” during the execution of this type of instruction. To supportdiverged threads, for each warp, the instruction scheduler 450 issuesinstructions for “active” threads included in the warp via an associatedwarp program counter (PC). By contrast, the instruction scheduler 450does not issue instructions for “inactive” threads included in the warpand, consequently the inactive threads are suspended.

The CBU 420 manages diverged threads and performs synchronizationoperations. For each thread included in each warp assigned to the SM310, the CBU 420 maintains a scheduling state 422. As shown, thescheduling states 422 are stored the CBU 420. In alternate embodiments,the scheduling states 422 may be stored in any memory or cache that isaccessible to the CBU 420 and the instruction schedulers 450. Each ofthe scheduling states 422 may include any number and type of values.

For a given thread, the associated scheduling state 422 specifieswhether the thread is exited, blocked, or unblocked. If the associatedscheduling states 422 is exited, then the thread is no longer capable ofexecuting any instructions. If the associated scheduling state 422 isblocked, then the thread is at a synchronization operation and isinactive. If the associated scheduling state 422 is unblocked, then thethread may or may not be at a synchronization operation and may or maynot be active. In alternate embodiments, the scheduling state 422 mayinclude any number and type of states, where at least one of the statesspecifies that the thread is blocked.

To ensure forward progress for all non-exited threads included in awarp, the CBU 420 activates and deactivates various threads included inthe warp based on one or more scheduling policies. As part ofdeactivating a thread, the CBU 420 sets a resumption program counter 472that is associated with the thread to specify the instruction that thethread is to execute when reactivated. The CBU 420 stores the resumptionprogram counters 472 in a register file 407 that is included in the coredata path 460. In alternate embodiments, each of the resumption programcounters 472 may be stored in any memory or cache that is accessible tothe CBU 420 and the associated instruction scheduler 450.

In particular, when there are no active threads included in the warp,the CBU 420 executes an “election process” that activates one or morethreads based on one or more scheduling policies, the scheduling states422, and the resumption program counters 472. As part of the electionprocess, the CBU 420 selects an inactive thread included in the warp forexecution based on the scheduling policies. The CBU 420 then sets thewarp PC associated with the warp equal to the resumption PC 422associated with the selected inactive thread. Subsequently, the CBU 442selects any other inactive threads included in the warp that areassociated with resumption PCs 442 that are equal to the warp PC. Foreach of the selected threads, if the scheduling state 442 is blocked,then the CBU 420 sets the scheduling state 442 to unblocked. Finally,the CBU 420 activates the selected threads.

One limitation of conventional PPUs that support divergent threads isthat the proper behavior of some instructions presupposes that thethreads in each warp are converged. When the threads are, in fact,diverged, then the results are unpredictable. For instance, the codethat is executing on the conventional PPU may produce incorrect resultsor terminate unexpectedly. Although some conventional compilers andconventional PPUs implement some level of synchronization functionality,that functionality is limited and does not guarantee convergence for allsituations. As a general matter, the implementation of certaininstructions may require a level of convergence across the differentthreads in a warp that cannot be maintained by conventional compiler andconventional hardware mechanisms included in conventional PPUs that arenormally tasked with ensuring such thread convergence.

Intra-Warp Synchronization

To comprehensively and effectively ensure proper execution of code andinstructions involving divergent threads, the SM 310 performs intra-warpsynchronization operations based on a synchronization instruction. Thesynchronization instruction is also referred to herein as a “WARPSYNC”instruction. Each of the threads that participates in a WARPSYNCinstruction individually specifies a “required” set of threads that areto be converged prior to executing the instruction immediately followingthe WARPSYNC instruction. As referred to herein, a “set of threads”includes between two threads and N threads, inclusive, where the warpincludes N threads. Further, each of the threads that participates inthe WARPSYNC instruction includes itself in the required set of threads.Each of the required set of threads may be specified as register, animmediate, or a constant.

Upon determining that a thread has reached a WARPSYNC instruction, theinstruction scheduler 450 determines whether the WARPSYNC instruction isa candidate for optimization. As referred to herein, a WARPSYNCinstruction is a candidate for optimization when each non-exited threadincluded in a warp participates in the WARPSYNC instruction, eachnon-exited thread specifies the required set of threads as an immediateor constant, and each non-exited thread is active. If the WARPSYNCinstruction is a candidate for optimization, then the instructionscheduler 450 sets the associated warp PC to specify the instructionfollowing the WARPSYNC instruction. In this fashion, the instructionscheduler 450 resolves the WARPSYNC instruction in one cycle.

If, however, the WARPSYNC instruction is not a candidate foroptimization, then the CBU 420 performs synchronization operations thatensure that the required set of threads execute the instructionfollowing the WARPSYNC instruction together. Notably, the CBU 420disregards any exited threads included in the required set of threadswhile executing the WARPSYNC instruction. Accordingly, as referred toherein, any exited threads included in the required set of threads areconsidered to have arrived the WARPSYNC instruction for the purpose ofWARPSYNC resolution. Initially, the CBU 420 concurrently andindependently processes each active thread that is executing theWARPSYNC instruction. For each active thread, the CBU 420 sets theassociated resumption program counter 472 to specify the WARPSYNCinstruction. The resumption program counter 472 does not impact thecurrent execution of the active thread. The CBU 420 then determines therequired set of threads associated with the active thread. If therequired set of threads does not include the active thread, then the CBU420 issues an error message and allows the thread to continue executing.

Subsequently, the CBU 420 performs comparison operations to determinewhether any of the threads included in the required set of threads areinactive. If any of the threads included in the required set of threadsare inactive, then the CBU 420 sets the scheduling state 422 associatedwith the active thread to blocked and deactivates the active thread.Because the associated resumption program counter 472 specifies theWARPSYNC instruction, the newly deactivated thread is blocked at theWARPSYNC instruction.

As a result of the comparison operations, either none of the threadsincluded in the warp are active or all the threads included in therequired set of threads are active. If none of the threads included inthe warp are active, then the CBU 420 performs an election process thatactivates one or more threads based on a scheduling policy, thescheduling states 422, and the resumption program counters 472. If,however, all the threads included in the required set of threads areactive, then the required set of threads are executing the WARPSYNCinstruction together. Since the required set of threads are converged,the CBU 420 sets the warp PC to specify the instruction immediatelyfollowing the WARPSYNC instruction. Advantageously, when each threadparticipating in the WARPSYNC instruction specifies the required set ofthreads as an immediate, the CBU 420 may resolve the WARPSYNCinstruction in approximately twelve cycles.

Note that the techniques described herein are illustrative rather thanrestrictive, and may be altered without departing from the broaderspirit and scope of the invention. Many modifications and variations onthe functionality provided by the CBU 420, the instruction scheduler450, the SM 310, and the WARPSYNC instruction will be apparent to thoseof ordinary skill in the art without departing from the scope and spiritof the described embodiments.

For instance, in alternate embodiments, the instruction scheduler 450may execute any portion (including all) of the election process.Further, the CBU 420 and the instruction scheduler 450 may execute anyother processes that implement any scheduling policies in anytechnically feasible fashion to ensure forward progress of threads. Invarious embodiments, the WARPSYNC instruction may be associated with aguard predicate and/or an input predicate.

The inventive concept described herein can be used to define differentinstruction pairs, where the second instruction in the pair depends onhaving proper convergence of two or more threads in a warp. Each“instruction pair” includes a WARPSYNC instruction associated with arequired set of threads in a warp and a subsequent instruction thatpresupposes that the required set of threads in the warp are converged.In this fashion, the instruction pair ensures proper operation of thesubsequent instruction. Examples of such instruction pairs include,without limitation, an inter-warp barrier (BAR_SYNC) instruction, ashuffle (SHFL_SYNC) instruction, and a voting (VOTE_SYNC) instruction,to name a few. The BAR_SYNC instruction synchronizes the threads in andbetween multiple warps. The SHFL_SYNC instruction enables directregister-to-register data exchange between the threads in a warp. TheVOTE_SYNC instruction generates a single vote result based on datareceived from threads in a warp.

In some embodiments, the CBU 420 supports register divergence for theWARPSYNC instruction. The CBU 420 activates the threads included in oneof the required set of threads and sets the resumption program counter472 for the threads included in any other required sets of threads tothe WARPSYNC instruction. The CBU 420 eventually schedules the threadsincluded in each of the other required sets of threads as per thescheduling policies. In this fashion, the CBU 420 independentlyconverges each of the required set of threads.

Synchronizing Different Threads Included within a Warp

FIG. 5 is an example instruction sequence performed by the streamingmultiprocessor 310 of FIG. 4 to synchronize different threads includedwithin a warp prior to concurrently executing a single subsequentinstruction, according to various embodiments of the present invention.The context of FIG. 5 is that each of the threads 3, 2, and 1 specifiesthe required set of threads for a WARPSYNC instruction as the threads 3,2, and 1.

An instruction sequence 500 begins at step 504, where threads 3 and 2are active, thread 1 is inactive, the resumption PC 472(1) associatedwith thread 1 specifies an XYZ instruction that is not equal to theWARPSYNC instruction, and the warp PC specifies the WARPSYNCinstruction. At step 506, the threads 3 and 2 execute the WARPSYNCinstruction. At step 508, because thread 1 is inactive, the CBU 420 setsthe resumption PC 472(3) associated with thread 3 to specify theWARPSYNC instruction, sets the scheduling state 422(3) associated withthread 3 to blocked, and deactivates thread 3. Similarly, the CBU 420sets the resumption PC 472(2) associated with thread 2 to specify theWARPSYNC instruction, sets the scheduling state 422(2) associated withthread 2 to blocked, and deactivates thread 2.

At step 510, eventually, as part of an election process, the CBU 420sets the warp PC to specify the XYZ instruction and activates thread 1.At step 512, after the instruction scheduler 450 issues one or moreinstructions (including the XYZ instruction) for thread 1, thread 1reaches the WARPSYNC instruction. At step 514, thread 1 executes theWARPSYNC instruction. At step 516, because threads 3 and 2 are inactive,the CBU 420 sets the resumption PC 472(1) associated with thread 1 tospecify the WARPSYNC instruction, sets the scheduling state 422(1)associated with thread 1 to blocked, and deactivates thread 1.

At step 520, eventually, as part of an election process, the CBU 420sets the warp PC to specify the WARPSYNC instruction, sets thescheduling states 422(3), 422(2), and 422(1) to unblocked, and activatesthreads 1, 2, and 3. At step 522, threads 1, 2, and 3 execute theWARPSYNC instruction concurrently. At step 524, because threads 1, 2,and 3 are all active, the CBU 420 sets the warp PC to specify theinstruction immediately following the WARPSYNC instruction. In thisfashion, the CBU 420 allows the converged and active threads 1, 2, and 3to proceed past the WARPSYNC instruction.

FIG. 6 is a flow diagram of method steps for synchronizing differentthreads included within a warp prior to concurrently executing a singlesubsequent instruction, according to various embodiments of the presentinvention. Although the method steps are described in conjunction withthe systems of FIGS. 1-4, persons skilled in the art will understandthat any system configured to perform the method steps, in any order,falls within the scope of the present invention. For explanatorypurposes only, FIG. 6 is described in the context of a single warp.Thus, the “active threads” referenced in the description are the activethreads included in that single warp. Confining the description of FIG.6 to the context of a single warp is not meant to limit the scope of thepresent invention in any way.

As shown, a method 600 begins at step 602, where one or more activethreads reach a WARPSYNC instruction. At step 604, the instructionscheduler 450 determines whether the WARPSYNC instruction is a candidatefor optimization. As described previous herein, a WARPSYNC instructionis a candidate for optimization when each non-exited thread participatesin the WARPSYNC instruction, each non-exited thread specifies therequired set of threads as an immediate or constant, and each non-exitedthread is active.

If, at step 604, the instruction scheduler 450 determines that theWARPSYNC instruction is a candidate for optimization, then the method600 proceeds to step 606. At step 606, the instruction scheduler 450sets the warp PC to the instruction immediately following the WARPSYNCinstruction, and the method 600 terminates.

If, however, at step 604, the instruction scheduler 450 determines thatthe WARPSYNC instruction is not a candidate for optimization, then themethod 600 proceeds directly to step 608. At step 608, concurrently andfor each active thread, the CBU 420 sets the associated resumptionprogram counter 472 to specify the WARPSYNC instruction. At step 610,concurrently and for each active thread, the CBU 420 determines therequired set of threads associated with the active thread. As part ofstep 610, if the CBU 420 determines that the required set of threadsassociated with a given active thread does not include the activethread, then the CBU 420 issues an error message and allows the threadto continue executing.

At step 612, concurrently and for each active thread, if any thread inthe associated required set of threads is inactive, the CBU 420deactivates and blocks the active thread. To block an active thread, theCBU 420 sets the scheduling state 422 associated with the active threadto blocked. Because the resumption PCs 472 associated with the activethreads specify the WARPSYNC instruction, any newly deactivated threadis blocked at the WARPSYNC instruction. As a result of step 612, eithernone of the threads are active or all the threads included in therequired set of threads are active.

If, at step 614, none of the threads are active, then the method 600proceeds to step 616. At step 616, the CBU 420 performs an electionprocess that selects one or more inactive threads to execute. Notably,for each of the selected threads, the resumption PC 472 specifies thesame instruction and, as part of step 616, the CBU 420 sets the warp PCequal to the specified instruction. At step 618, for each of theselected threads, the CBU 420 sets the associated scheduling state 422to unblocked and activates the thread. The method 600 then returns tostep 602, where one or more active threads eventually reach and executethe WARPSYNC instruction.

If, however, at step 614, the threads included in the required set ofthreads are active, then the method 600 proceeds directly to step 620.At step 620, the CBU 420 sets the warp PC to the instruction immediatelyfollowing the WARPSYNC instruction, and the method 600 terminates.

In sum, a warp synchronization (WARPSYNC) instruction configures astreaming microprocessor to converge a set of threads that are includedin a warp. Upon executing the WARPSYNC instruction, for each activethread, a convergence barrier unit (CBU) sets an associated resumptionprogram counter (PC) equal to the WARPSYNC instruction. Concurrently andfor each active thread, the CBU performs comparison operations todetermine whether any of the threads in the required set of threads areinactive. If any of the threads in the required set of threads areinactive, then the CBU blocks and deactivates the active thread. Becauseof the resumption PC, the newly deactivated thread is blocked at theWARPSYNC instruction.

As a result of the comparison operations, either none of the threadsincluded in the warp are active or all the threads included in therequired set of threads are active. If none of the threads included inthe warp are active, then the CBU performs an election operation thatselects one or more inactive threads, where the resumption PC associatedwith each of the selected inactive threads specifies the sameinstruction. The CBU sets the warp PC equal to the specifiedinstruction, unblocks any of the selected threads that are blocked, andactivates the selected threads. If, however, all the threads included inthe required set of threads are active, then the required set of threadsare executing the WARPSYNC instruction together. Since the required setof threads are converged, the CBU sets the warp program counter to theinstruction immediately following the WARPSYNC instruction.

Advantageously, the disclosed techniques enable a PPU to properlyexecute code and instructions that rely on the convergence of differentthreads included within a warp. By contrast, conventional compiler andconventional hardware mechanisms included in conventional PPUs that arenormally tasked with ensuring such thread convergence are unable toguarantee the thread convergence. Because conventional compilers andconventional PPUs are not always able to ensure that threads within awarp are converged when required for proper execution of code, code thatis executing on a conventional PPU may produce incorrect results orterminate unexpectedly.

The descriptions of the various embodiments have been presented forpurposes of illustration, but are not intended to be exhaustive orlimited to the embodiments disclosed. Many modifications and variationswill be apparent to those of ordinary skill in the art without departingfrom the scope and spirit of the described embodiments.

Aspects of the present embodiments may be embodied as a system, methodor computer program product. Accordingly, aspects of the presentdisclosure may take the form of an entirely hardware embodiment, anentirely software embodiment (including firmware, resident software,micro-code, etc.) or an embodiment combining software and hardwareaspects that may all generally be referred to herein as a “module” or“system.” Furthermore, aspects of the present disclosure may take theform of a computer program product embodied in one or more computerreadable medium(s) having computer readable program code embodiedthereon.

Any combination of one or more computer readable medium(s) may beutilized. The computer readable medium may be a computer readable signalmedium or a computer readable storage medium. A computer readablestorage medium may be, for example, but not limited to, an electronic,magnetic, optical, electromagnetic, infrared, or semiconductor system,apparatus, or device, or any suitable combination of the foregoing. Morespecific examples (a non-exhaustive list) of the computer readablestorage medium would include the following: an electrical connectionhaving one or more wires, a portable computer diskette, a hard disk, arandom access memory (RAM), a read-only memory (ROM), an erasableprogrammable read-only memory (EPROM or Flash memory), an optical fiber,a portable compact disc read-only memory (CD-ROM), an optical storagedevice, a magnetic storage device, or any suitable combination of theforegoing. In the context of this document, a computer readable storagemedium may be any tangible medium that can contain, or store a programfor use by or in connection with an instruction execution system,apparatus, or device.

Aspects of the present disclosure are described above with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems) and computer program products according to embodiments of thedisclosure. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer program instructions. These computer program instructions maybe provided to a processor of a general purpose computer, specialpurpose computer, or other programmable data processing apparatus toproduce a machine. The instructions, when executed via the processor ofthe computer or other programmable data processing apparatus, enable theimplementation of the functions/acts specified in the flowchart and/orblock diagram block or blocks. Such processors may be, withoutlimitation, general purpose processors, special-purpose processors,application-specific processors, or field-programmable gate arrays.

The flowchart and block diagrams in the figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods and computer program products according to variousembodiments of the present disclosure. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing the specified logical function(s). It should also be notedthat, in some alternative implementations, the functions noted in theblock may occur out of the order noted in the figures. For example, twoblocks shown in succession may, in fact, be executed substantiallyconcurrently, or the blocks may sometimes be executed in the reverseorder, depending upon the functionality involved. It will also be notedthat each block of the block diagrams and/or flowchart illustration, andcombinations of blocks in the block diagrams and/or flowchartillustration, can be implemented by special purpose hardware-basedsystems that perform the specified functions or acts, or combinations ofspecial purpose hardware and computer instructions.

While the preceding is directed to embodiments of the presentdisclosure, other and further embodiments of the disclosure may bedevised without departing from the basic scope thereof, and the scopethereof is determined by the claims that follow.

What is claimed is:
 1. A computer-implemented method for synchronizing aplurality of threads, the method comprising: determining that a firstthread included in a thread group has arrived at a synchronizationinstruction; in response to the first thread arriving at thesynchronization instruction, determining a plurality of threads includedin the thread group that are to be synchronized, wherein the pluralityof threads is specified by the first thread and includes at least thefirst thread and a second thread; determining that the second threadincluded in the plurality of threads has not yet arrived at thesynchronization instruction; configuring the first thread to stopexecuting instructions; issuing at least one additional instruction forthe second thread; determining that all the threads included in theplurality of threads have arrived at the synchronization instruction;and causing all the threads included in the plurality of threads toexecute a first subsequent instruction.
 2. The computer-implementedmethod of claim 1, wherein the synchronization instruction and the firstsubsequent instruction comprise an instruction pair.
 3. Thecomputer-implemented method of claim 1, wherein the first subsequentinstruction comprises a shuffle instruction that enables directregister-to-register data exchange between the plurality of threads or avote instruction that generates a single vote result based on datareceived from the plurality of threads.
 4. The computer-implementedmethod of claim 1, wherein the first subsequent instruction comprises aninter-thread group barrier instruction that involves the plurality ofthreads and at least one other plurality of threads.
 5. Thecomputer-implemented method of claim 1, wherein configuring the firstthread to stop executing instructions comprises setting scheduling stateassociated with the first thread to values that cause instructions notto be issued to the first thread, and deactivating the first thread. 6.The computer-implemented method of claim 1, further comprising, prior todetermining that the second thread has not yet arrived at thesynchronization instruction, setting a first resumption program counterassociated with the first thread to specify the synchronizationinstruction.
 7. The computer-implemented method of claim 1, furthercomprising, prior to determining that all the threads included in theplurality of threads have arrived at the synchronization instruction:setting a thread group program counter to specify the synchronizationinstruction based on a first resumption program counter associated withthe first thread; and for each thread included in the plurality ofthreads, determining that a resumption program counter associated withthe thread is equal to the synchronization instruction, and causing thethread to execute instructions based on the thread group programcounter.
 8. The computer-implemented method of claim 7, wherein causingthe thread to execute instructions based on the thread group programcounter comprises setting scheduling state associated with the thread tovalues that cause instructions to be issued to the thread.
 9. Thecomputer-implemented method of claim 1, wherein determining that all thethreads included in the plurality of threads have arrived at thesynchronization instruction comprises, for each thread included in theplurality of threads, determining that the thread is no longer capableof executing any instructions or has begun executing the synchronizationinstruction.
 10. The computer-implemented method of claim 1, whereincausing all the threads included in the plurality of threads to executethe first subsequent instruction comprises setting a thread groupprogram counter to specify the first subsequent instruction.
 11. Asystem configured to synchronize a plurality of threads, the systemcomprising: an instruction cache that stores a plurality ofinstructions; an instruction scheduler coupled to the instruction cache;and a convergence barrier unit that is coupled to the instruction cache,wherein the convergence barrier unit: determines that a first threadincluded in a thread group has arrived at a synchronization instructionincluded in the plurality of instructions; in response to the firstthread arriving at the synchronization instruction, determines aplurality of threads included in the thread group that are to besynchronized, wherein the plurality of threads is specified by the firstthread and includes at least the first thread and a second thread;determines that a second thread included in the plurality of threads hasnot yet arrived at the synchronization instruction; configures the firstthread to stop executing instructions; issues at least one additionalinstruction for the second thread; determines that all the threadsincluded in the plurality of threads have arrived at the synchronizationinstruction; and causes all the threads included in the plurality ofthreads to execute a first subsequent instruction included in theplurality of instructions.
 12. The system of claim 11, wherein thesynchronization instruction and the first subsequent instructioncomprise an instruction pair.
 13. The system of claim 11, whereincausing all the threads included in the plurality of threads to executethe first subsequent instruction results in one or more directregister-to-register data exchanges between the plurality of threads.14. The system of claim 11, where causing all the threads included inthe plurality of threads to execute the first subsequent instructiongenerates a single vote result based on data received from the pluralityof threads.
 15. The system of claim 11, wherein causing all the threadsincluded in the plurality of threads to execute the first subsequentinstruction synchronizes the plurality of threads and at least one otherplurality of threads.
 16. The system of claim 11, wherein theconvergence barrier unit, prior to determining that the second threadhas not yet arrived at the synchronization instruction, sets a firstresumption program counter associated with the first thread to specifythe synchronization instruction.
 17. The system of claim 11, wherein theconvergence barrier unit, prior to determining that all the threadsincluded in the plurality of threads have arrived at the synchronizationinstruction: sets a thread group program counter to specify thesynchronization instruction based on a first resumption program counterassociated with the first thread; and for each thread included in theplurality of threads, determines that a resumption program counterassociated with the thread is equal to the synchronization instruction,and causes the thread to execute instructions based on the thread groupprogram counter.
 18. The system of claim 17, wherein the convergencebarrier unit causes the thread to execute instructions based on thethread group program counter by setting scheduling state associated withthe thread to values that cause instructions to be issued to the thread.19. The system of claim 17, wherein the convergence barrier unitdetermines that all the threads included in the plurality of threadshave arrived at the synchronization instruction by, for each threadincluded in the plurality of threads, determining that the thread is nolonger capable of executing any instructions or has begun executing thesynchronization instruction.
 20. One or more non-transitorycomputer-readable storage media including instructions that, whenexecuted by one or more processors, cause the one or more processors toperform the steps of: determining that a first thread included in athread group has arrived at a synchronization instruction; in responseto the first thread arriving at the synchronization instruction,determining a plurality of threads included in the thread group that areto be synchronized, wherein the plurality of threads is specified by thefirst thread and includes at least the first thread and a second thread;determining that a second thread included in the plurality of threadshas not yet arrived at the synchronization instruction; configuring thefirst thread to stop executing instructions; issuing at least oneadditional instruction for the second thread; determining that all thethreads included in the plurality of threads have arrived at thesynchronization instruction; and causing all the threads included in theplurality of threads to execute a first subsequent instruction.